package com.atguigu.mr2;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
//将表中的数据中的color转移到其他位置
public class Fruit2Driver implements Tool {
    private Configuration cfg=null;
    public int run(String[] args) throws Exception {
        //1 获取job对象
        Job job = Job.getInstance(cfg);
        //2 设置主类路径
        job.setJarByClass(Fruit2Driver.class);
        //3 设置mapper&输出kv类型
        TableMapReduceUtil.initTableMapperJob("fruit",new Scan(),Fruit2Mapper.class, ImmutableBytesWritable.class, Put.class,job);
        //4 设置reducer&输出表
        TableMapReduceUtil.initTableReducerJob("fruit3",Fruit2Reducer.class,job);
        //5 提交任务
        boolean result = job.waitForCompletion(true);
        //注意：打印的代码，显示为0的时候为正常，显示为其他的时候，说名存在问题。
        return result?0:1;
    }

    public void setConf(Configuration configuration) {
        cfg=configuration;
    }

    public Configuration getConf() {
        return cfg;
    }

    public static void main(String[] args) {
        Configuration configuration = HBaseConfiguration.create();
        //configuration.set("hbase.zookeeper.quorum","zhiyou001,zhiyou002,zhiyou003");
        try {
            /*Configuration configuration=new Configuration();*/
            ToolRunner.run(configuration,new Fruit2Driver(),args);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
